USE [ArtsShop]
GO

/****** Object:  StoredProcedure [dbo].[getAllCategories]    Script Date: 02/23/2011 07:32:47 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AddItemToCart]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[AddItemToCart]
GO

USE [ArtsShop]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Francis A
-- Create date: 13/04/2011
-- Description:	Get all active categories
-- =============================================
CREATE PROCEDURE [dbo].[AddItemToCart]
	-- Add the parameters for the stored procedure here
	@cartId nvarchar(255),
	@productId int,
	@quantity int
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	if not exists(select 1 from shoppingCart where cartId=@cartId and productId=@productId)
--		begin
		insert into shoppingCart values
		(@cartId,
		 @quantity,
		 @productId,
		 GETDATE()	
		)				
--		end
	else
		update shoppingCart set quantity=(quantity+@quantity) where cartId=@cartId and productId=@productId
			
	
END




GO


